var game = {
	requestNBADay:0,
	requestCBARound:0,
	nbaObject:'#nbaBox',
	cbaObject:'#cbaBox',
	init:function(params){    
        if (typeof(params.nbaObject) != 'undefined' && params.nbaObject) this.nbaObject = params.nbaObject;      
        if (typeof(params.cbaObject) != 'undefined' && params.cbaObject) this.cbaObject = params.cbaObject;      
		if (this.nbaObject.substr(0,1)!='#') this.nbaObject = '#'+this.nbaObject.substr(1);
		if (this.cbaObject.substr(0,1)!='#') this.cbaObject = '#'+this.cbaObject.substr(1);
        if (typeof(params.init_day) != 'undefined' && params.init_day) this.requestNBADay = params.requestDay;
        if (typeof(params.cbaRound) != 'undefined' && params.cbaRound) this.requestCBARound = params.cbaRound;
	},
	nextday:function(){
        this.requestNBADay = parseInt(this.requestNBADay) + 1;
        this.loadNBAGame();
        return false;
	},
	prevday:function(){
		this.requestNBADay = parseInt(this.requestNBADay) - 1;
		this.loadNBAGame();
        return false;
	},
    switchLeague: function(league)
    {
        if ('NBA'==league)
        {
            $('#nba_btn').attr('class', 'boxScorePage_on');
            $('#cba_btn').attr('class', 'boxScorePage_off');
            if (!$(this.nbaObject).html())
            {
                this.loadNBAGame();
            }
            $(this.cbaObject).hide();
            $(this.nbaObject).show();
        }
        if ('CBA'==league)
        {
            $('#nba_btn').attr('class', 'boxScorePage_off');
            $('#cba_btn').attr('class', 'boxScorePage_on');
            if (!$(this.cbaObject).html())
            {
                this.loadCBAGame(this.requestCBARound);
            }
            $(this.nbaObject).hide();
            $(this.cbaObject).show();
        }
    },
	loadNBAGame:function()
	{
        params = {'league': 'NBA', 'day': this.requestNBADay};
        this.loadGame(params);
	},
    prevRound: function(round)
    {
        this.requestCBARound = round;
        this.loadCBAGame();
    },
    nextRound: function(round)
    {
        this.requestCBARound = round;
        this.loadCBAGame();
    },
	loadCBAGame:function(){
        params = {'league': 'CBA', 'round': this.requestCBARound};
        this.loadGame(params);
    },
    initGame: function(){
        params = {};
        this.loadGame(params);
    },
    loadGame: function(params){
        $.ajax({
            type:'GET',
            url:'/boxscore/boxscore.php',
            data: params,
            success: function (ret){
                if (ret)
                {
                    reObject = jQuery.parseJSON(ret);
                    if ('NBA' == reObject.league)
                    {
                        $('#cba_btn').attr('class', 'boxScorePage_off');
                        $('#nba_btn').attr('class', 'boxScorePage_on');
                        $('#nbaBox').html(reObject.html);
                        $('#nbaBox').show();
                        $('#cbaBox').hide();
                    }
                    else if('CBA' == reObject.league)
                    {
                        $('#nba_btn').attr('class', 'boxScorePage_off');
                        $('#cba_btn').attr('class', 'boxScorePage_on');
                        $('#cbaBox').html(reObject.html);
                        $('#cbaBox').show();
                        $('#nbaBox').hide();
                    }
                }
            }
        });
    }
};
